<?php
/**
 * IndexController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action
{
    /**
     * The default action - show the home page
     */
    public function indexAction() {
    	
    	$auctionService = Application_Service_Auction::getInstance();
    	$winnerService = Application_Service_Winner::getInstance();
    	
    	///////////////////////////////////
    	// 获取竞拍商品
    	if(!isset($_GET['auction_id'])) {    	// 登录首页，没有带参数
    		
	    	$auctions = $auctionService->getActiveAuction();
	    	$this->view->auctions = $auctions;
	    	
    	} else {								// 选择竞拍商品，带参数
    		
    		$auctionId = $_GET['auction_id'];
    		$auctions = $auctionService->getActiveAuctionOrId($auctionId);
    		$this->view->auctions = $auctions;
    	}

    	//////////////////////////////////
    	// 获取最近中拍者，中拍商品信息
    	$count = Application_Model_Constants::$RECENT_WINNER_NUM;
    	$winners = $winnerService->getRecentWinner($count);
    	
    	$this->view->winners = $winners;
    	
    }
    
    public function bidAction() {
    
    	$auctionService = Application_Service_Auction::getInstance();
    	
//    	// 验证用户是否登录
//    	if(!isset($_SESSION['normal_user'])) {
//    		echo "请登录";
//    		return;
//    	}
//    	
		echo "test";
    }
    
    public function platformAction() {
    	//关闭layout 和 view(不需要phtml)
		Zend_Layout::getMvcInstance()->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		
    	//get the platform type
    	$args = $_GET['platform'];
    	$args = explode('_', $args);
    	$act = $args[0];
    	$platform = $args[1];
    	if(! $platform || ! $act) {
    		$this->_redirect('/index'); 
    	}
    	//get user
    	$normal_user = Application_Service_Login::getInstance()->callback($platform, $act);
    	if($act == 'callback') {
    		if($normal_user) {
    		if (! isset($_SESSION)) {
				session_start ();
			}
    		$_SESSION['normal_user'] = $normal_user;
    		}
    		echo '<script>window.opener.location.href="/index";window.close();</script>';
    	}
    }
    
    public function logoutAction() {
    	//关闭layout 和 view(不需要phtml)
		Zend_Layout::getMvcInstance()->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		//注销
    	Application_Service_Login::getInstance()->logout();
    	$this->_redirect('/index');
    }
}
